package fasttask

import (
	"cloud_worm/util/umodels/mysqldb/dbtask"
	"strings"
	"cloud_worm/util/umodels/mysqldb/dbmanager"
	"cloud_worm/wormweb/controllers/ctrinner/taskqueue"
)

// ScanWolAgentTask 扫描主机的任务
type ScanWolAgentTask struct {
	WormIds 		[]*dbmanager.WormId
	Task 			*dbtask.WeaponTask
}

// Done 任务执行
func (s *ScanWolAgentTask) Done()  {
	// weapon
	wpsName := strings.Split(s.Task.WeaponsName, ",")

	// item数据
	sumItem := len(s.WormIds) * len(wpsName)
	notifyChan := WaitTaskFinish(s.Task, sumItem, IsNeedTaskAlertDeal(s.Task.WeaponsName))

	// 将item下发异步队列处理
	for _, m := range s.WormIds {
		for _, wp := range wpsName {
			taskItem := &TaskItem{
				NotifyChan: notifyChan,
				TaskId: s.Task.TaskId,
				WormId: m.AgentId,
				WeaponName: wp,
				Input: "",                              // todo：考虑何时可以设置入参的设计
			}
			//logs.Debug(fmt.Sprintf("%s, %s, task: %s", taskItem.WeaponName, taskItem.WolId, taskItem.TaskId))
			taskqueue.FastQueInst().MsgQ.Push(taskItem)
		}
	}
	return
}
